package cn.hu.org.controller;

import cn.hu.basic.util.AjaxResult;
import cn.hu.basic.util.PageList;
import cn.hu.org.domain.DictionaryDetail;
import cn.hu.org.query.DictionaryDetailQuery;
import cn.hu.org.service.IDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dictionary_detail")
public class DictionaryDetailController {
    @Autowired
    private IDictionaryDetailService dictionaryDetailService;

    @GetMapping("/{id}")
    public DictionaryDetail findOne(@PathVariable Long id){
        return dictionaryDetailService.findById(id);
    }

    @GetMapping
    public List<DictionaryDetail> findAll(){
        return dictionaryDetailService.findAll();
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody DictionaryDetail dictionaryDetail){
            if(dictionaryDetail.getId() == null){
                dictionaryDetailService.add(dictionaryDetail);
            }else {
                dictionaryDetailService.update(dictionaryDetail);
            }
            return AjaxResult.getInstance();
    }

    @PostMapping
    public PageList<DictionaryDetail> getListByQuery(@RequestBody DictionaryDetailQuery query){
        return dictionaryDetailService.listByQuery(query);
    }

    @DeleteMapping("/{id}")
    public AjaxResult deleteDep(@PathVariable Long id){
        dictionaryDetailService.delete(id);
            return AjaxResult.getInstance();
    }

    @PatchMapping
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        dictionaryDetailService.patchDelete(ids);
            return AjaxResult.getInstance();
    }

}
